libxenlight: don't use the cloning logic in dm_xenstore_record_pid.
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 8 Jan 2010 11:46:17 +0000 (11:46 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 8 Jan 2010 11:46:17 +0000 (11:46 +0000)
use call to lowlevel functions to do the same things.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_xshelp.c

index a49371540cb97ba7a27ff312f1d8989de425dd8c..da09106b1c4ba34a49c74f0f306e0d8c396c025d 100644 (file)
@@ -728,33 +728,21 @@ static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
 void dm_xenstore_record_pid(struct libxl_ctx *ctx, void *for_spawn,
                             pid_t innerchild) {
     struct libxl_device_model_starting *starting = for_spawn;
-    struct libxl_ctx clone;
     char *kvs[3];
-    int rc, cloned;
-
-    if (libxl_clone_context_xs(ctx, &clone)) {
-        XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context");
-        /* Throw a prayer fallback */
-        clone = *ctx;
-        clone.xsh = xs_daemon_open();
-        cloned = 0;
-    } else {
-        cloned = 1;
-    }
+    int rc;
+    struct xs_handle *xsh;
+
+    xsh = xs_daemon_open();
     /* we mustn't use the parent's handle in the child */
 
     kvs[0] = "image/device-model-pid";
-    kvs[1] = libxl_sprintf(&clone, "%d", innerchild);
+    asprintf(&kvs[1], "%d", innerchild);
     kvs[2] = NULL;
-    rc = libxl_xs_writev(&clone, XBT_NULL, starting->dom_path, kvs);
-    if (rc) XL_LOG_ERRNO(&clone, XL_LOG_ERROR,
-                         "Couldn't record device model pid %ld at %s/%s",
-                         (unsigned long)innerchild, starting->dom_path, kvs);
-    if (cloned) {
-        libxl_discard_cloned_context_xs(&clone);
-    } else {
-        xs_daemon_close(clone.xsh);
-    }
+
+    rc = xs_writev(xsh, XBT_NULL, starting->dom_path, kvs);
+    if (rc)
+        return;
+    xs_daemon_close(xsh);
 }
 
 static int libxl_vfb_and_vkb_from_device_model_info(struct libxl_ctx *ctx,
index 8b649658a3aa4ef2446317fd8be04186a58fb471..1f7e64af6b4fdd5741c4a658b664838e2bf6b804 100644 (file)
@@ -93,6 +93,8 @@ typedef struct {
                 (u)[0], (u)[1], (u)[2], (u)[3], (u)[4], (u)[5], (u)[6], (u)[7], \
                 (u)[8], (u)[9], (u)[10], (u)[11], (u)[12], (u)[13], (u)[14], (u)[15])
 
+int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]);
+
 /* memory allocation tracking/helpers */
 int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to);
 static inline int libxl_clone_context_xs(
index 87c494a4a516610e2e79c3af91ab852821d843d4..3c065a067b69b3a91e7b2035e4e4325a0cd5dd33 100644 (file)
 #include "libxl.h"
 #include "libxl_internal.h"
 
+int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[])
+{
+    char *path;
+    int i;
+
+    if (!kvs)
+        return 0;
+
+    for (i = 0; kvs[i] != NULL; i += 2) {
+        asprintf(&path, "%s/%s", dir, kvs[i]);
+        if (path) {
+            int length = strlen(kvs[i + 1]);
+            xs_write(xsh, t, path, kvs[i + 1], length);
+            free(path);
+        }
+    }
+    return 0;
+}
+
 char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, int length)
 {
     char **kvs;